<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 19-3-6
 * Time: 下午2:29
 */

namespace common\components\icbcapi\sdk;


class IcbcCa
{
    public static function sign($content, $privatekey, $password)
    {

        if (!extension_loaded('infosec')) {
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                dl('php_infosec.dll');
            } else {
                dl('infosec.so');
            }
        } else {
            //echo "loaded infosec module success <br/>";
        }
        $plaint = $content;
        if (strlen($plaint) <= 0) {
            echo "WARNING : no source data input";
            throw new \Exception("no source data input");
        }
        $contents = base64_decode($privatekey);
        $key = substr($contents, 2);
        $pass = $password;
        if (strlen($pass) <= 0) {
            echo "WARNING : no key password input";
            throw new \Exception("no key password input");
        } else {
            /*var_dump($plaint);
            var_dump($key);
            var_dump($pass);
            exit;*/
            $signature = sign($plaint, $key, $pass);
            $code = current($signature);
            $len = next($signature);
//            $signcode = base64enc($code);
            $signcode = base64_encode($code);
            return current($signcode);
            /*			echo "signature : ",current($signcode),"\n";
                    echo "signature len: ",$len,"\n";*/
        }

    }


    public static function verify($content, $publicKey, $password)
    {

    }
}